# $Id$
# Maintainer: Pierre Schmitz <pierre@archlinux.de>

pkgname=composer
pkgver=1.5.1
pkgrel=1
pkgdesc="Dependency Manager for PHP"
arch=('any')
license=('MIT')
url='https://getcomposer.org/'
depends=('php')
makedepends=('git')
checkdepends=('git' 'mercurial' 'parallel')
replaces=('php-composer')
conflicts=('php-composer')
provides=('php-composer')
source=("${pkgname}::git+https://github.com/composer/composer.git#tag=${pkgver}"
        "${pkgname}-${pkgver}.phar::https://getcomposer.org/download/${pkgver}/composer.phar")
md5sums=('SKIP'
         '43e330d8c79d008dd810f0479f5cb003')

prepare() {
	cd ${srcdir}/${pkgname}

	php ${srcdir}/${pkgname}-${pkgver}.phar -n install --no-dev --prefer-dist
}

build() {
	cd ${srcdir}/${pkgname}

	php -d phar.readonly=Off bin/compile
}

check() {
	cd ${srcdir}/${pkgname}

	# check if the upstream build and ours differ
	diff -q ${srcdir}/${pkgname}-${pkgver}.phar composer.phar

	git config --global user.email "${USER}@${HOST}"
	git config --global user.name "${USER}"

	# Install the dev dependencies to run the unit tests
	bin/composer -n install --prefer-dist

	ls -d tests/Composer/Test/* | parallel --gnu --keep-order vendor/bin/phpunit {} \;
}

package() {
	cd ${srcdir}/${pkgname}

	install -Dm644 LICENSE ${pkgdir}/usr/share/licenses/${pkgname}/LICENSE
	install -Dm755 composer.phar ${pkgdir}/usr/bin/composer
}
